/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package fmon.util;

//~--- JDK imports ------------------------------------------------------------

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

/**
 *
 * @author jio
 */
public class HelperClass {
    public static long retrieveChecksum(String filename) {
        long checksum = 0;

        try {
            CheckedInputStream cis      = null;
            long               fileSize = 0;

            try {
                FileInputStream fis = new FileInputStream(filename);

                cis = new CheckedInputStream(fis, new CRC32());

                File f = new File(filename);

                fileSize = f.length();
            } catch (FileNotFoundException e) {
                System.err.println("File not found or permission denied: " + filename);

                return checksum;
            }

            byte[] buf = new byte[128];

            System.out.println("Processing... " + filename);

            while (cis.read(buf) >= 0) {}

            checksum = cis.getChecksum().getValue();
            cis.close();
            System.out.println(checksum + " " + filename);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return checksum;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
